﻿using System;
using System.IO;
using System.Reflection;
using Microsoft.Office.Interop.Word;

namespace Wikey.Utilities
{
    public class WordToHtml
    {

        public static string Export(string file)
        {
            file = @"D:\OpenSource\Wikey\Wikey.Web.Mvc\Uploads\Modifying EOL Login Screen.doc";
            string exportFile = @"D:\OpenSource\Wikey\Wikey.Web.Mvc\Uploads\Export\export.html";

            Application app = new Application();
            app.Visible = false;
            Object o = Missing.Value;
            object docFile = file;
            _Document doc = app.Documents.Open(ref docFile, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref
                        o);
            object fileName = exportFile;
            object format = 8;//Html
            doc.SaveAs(ref fileName, ref format, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o);
            object t = true;
            app.Quit(ref t, ref o, ref o);

            TextReader reader = new StreamReader(exportFile);

            return reader.ReadToEnd();
        }


    }
}
